﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;

namespace Touch2Like.Web
{
    public class Global : System.Web.HttpApplication
    {

        void Application_Start(object sender, EventArgs e)
        {
            // Code that runs on application startup

        }

        void Application_End(object sender, EventArgs e)
        {
            //  Code that runs on application shutdown
            //for (int i = 0; i < Session.Count; i++)
            //{
            //    Session[i] = null;
            //}

        }

        void Application_Error(object sender, EventArgs e)
        {
            //Response.Redirect("~/ErrorPage.aspx");
        }

        void Session_Start(object sender, EventArgs e)
        {
            // Code that runs when a new session is started
        }

        void Application_BeginRequest(Object sender, EventArgs e)
        {
            /*string server = HttpContext.Current.Request.ServerVariables["SERVER_NAME"];
              bool https = HttpContext.Current.Request.ServerVariables["HTTPS"] != "off";
             //If its not https and is not Default.aspx then redirect to https site
              if ( ( !( https ) )
                  && ( !( Request.Url.AbsoluteUri.ToUpper( ).IndexOf( "DEFAULT.ASPX" ) > 0 ) ) )
              {
                  string newUrl = Request.Url.AbsoluteUri.Replace( "http:", "https:" );
                  Response.Redirect( newUrl );
              }
          */
        }

        void Application_EndRequest(Object sender, EventArgs e)
        {
            //StringBuilder sb=new StringBuilder();

            //sb.Append("<script language='javascript'> <!-- \n");
            //sb.Append("setTimeout('window.loading.style.visibility=\"hidden\"',500);\n");
            //sb.Append("--> </").Append("script>\n");
            //Response.Write(sb.ToString());
        }

        void Session_End(object sender, EventArgs e)
        {
            // Code that runs when a session ends. 
            // Note: The Session_End event is raised only when the sessionstate mode
            // is set to InProc in the Web.config file. If session mode is set to StateServer 
            // or SQLServer, the event is not raised.
            for (int i = 0; i < Session.Count; i++)
            {
                Session[i] = null;
            }
        }
    }
}